package com.example.t1;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class ShowActivity extends AppCompatActivity {

    int[] p = {R.mipmap.photo1,R.mipmap.photo2,R.mipmap.photo3};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show);
        Intent intent = getIntent();
        String info = intent.getStringExtra("name");
        int timeNum = intent.getIntExtra("timeNum",10);
        TextView name = findViewById(R.id.name);
        TextView time = findViewById(R.id.spdTime);
        ImageView photo = findViewById(R.id.show_photo);
        photo.setImageResource(p[Chessboard.photo-1]);
        name.setText(info);
        String tmp =String.valueOf(timeNum/60)+":"+String.valueOf(timeNum%60);
        time.setText(tmp);

        DatabaseHelper helper = new DatabaseHelper(this,"demo.db",null,1);
        SQLiteDatabase db = helper.getReadableDatabase();
        String sql = "select name,time,photo from rank order by time";
        Cursor cursor = db.rawQuery(sql,null);
        cursor.moveToFirst();
        TextView show_view = findViewById(R.id.show_rank);
        int n=0;
        while(!cursor.isAfterLast()) {
            String str = cursor.getString(cursor.getColumnIndex("name"));
            int a = cursor.getInt(cursor.getColumnIndex("photo"));
            int b = cursor.getInt(cursor.getColumnIndex("time"));
            Log.i("xx", str + " " + a + " " + b);
            ++n;
            show_view.append("第"+n+"名       "+str+"       用时"+b+"秒 \n");
            cursor.moveToNext();
        }
    }
    public void restart(View view){
        /*Chessboard.init();
        GameFragment gameFragment = new GameFragment();
        gameFragment.repaint();
        finish();
         */
        System.exit(0);
    }
}